package com.book.utils;

import com.book.utils.JWT.JwtInterceptor;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 给全部的接口添加 /api  前缀
 * 配置统一拦截器
 */
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        //        给接口添加统一的前缀  /api
        configurer.addPathPrefix("/api",clazz->clazz.isAnnotationPresent(RestController.class));
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(JwtInterceptor).addPathPatterns("/api/**")//加入拦截的接口
                .excludePathPatterns("/api/admin/login");//排除拦截的接口   登陆 注册
    }
}
